package com.ujs.edu.demo.controller;

import com.ujs.edu.demo.dao.BcAdminMapper;
import com.ujs.edu.demo.dataobject.BcAdmin;
import com.ujs.edu.demo.util.MSUtil;
import com.ujs.edu.demo.util.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class SignupController {

    @Autowired
    private BcAdminMapper bcAdminMapper;

    @RequestMapping(path = "/signup")
    public ModelAndView signup(){
        ModelAndView view=new ModelAndView();
        view.setViewName("signup");
        return view;
    }

    //注册
    @RequestMapping(path = "/tosignup")
    @ResponseBody
    public Result tosignup(BcAdmin bcAdmin) throws Exception {
        Result result=new Result();

        String password=MSUtil.md5(bcAdmin.getPassword(),"xhj");
        bcAdmin.setPassword(password);
        int in=bcAdminMapper.insert(bcAdmin);
        if (in==1){
            result.setStatus(1);
            result.setMsg("注册成功");
        }else {
            result.setStatus(0);
            result.setMsg("注册失败");
        }
        return result;
    }

}
